//
//  MainViewController.m
//  FinalMes
//
//  Created by Roger Plana Casadellà on 07/07/11.
//  Copyright 2011 Champions Freak. All rights reserved.
//

#import "MainViewController.h"
#import "LoginViewController.h"
#import "DashboardViewController.h"
#import "MisListasViewController.h"

@implementation MainViewController

@synthesize loginView = _loginView;
@synthesize dashboardView = _dashboardView;
@synthesize misListasView = _misListasView;

@synthesize hashID = _hashID;
@synthesize userName =_userName;

// Make this class a singleton class
SYNTHESIZE_SINGLETON_FOR_CLASS(MainViewController);

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
    }
    return self;
}

#pragma mark - Change Section Calls

- (void)LoadLogin:(UIViewController *)vista
{
    //Treiem la vista anterior i fem un reset de totes les vistes
    [[vista view] removeFromSuperview];
    [self resetAll];
    
    //Carreguem la nova vista
    self.loginView = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
	[self.view insertSubview:[self.loginView view] atIndex:0];
}

- (void)LoadDashboard:(UIViewController *)vista
{
    //Treiem la vista anterior i fem un reset de totes les vistes
    [[vista view] removeFromSuperview];
    [self resetAll];
    
    //Carreguem la nova vista
    self.dashboardView = [[DashboardViewController alloc] initWithNibName:@"DashboardView" bundle:nil];
    [self.view insertSubview:[self.dashboardView view] atIndex:0];
}

- (void)LoadMisListas:(UIViewController *)vista
{
    //Treiem la vista anterior i fem un reset de totes les vistes
    [[vista view] removeFromSuperview];
    [self resetAll];
    
    //Carreguem la nova vista
    self.misListasView = [[MisListasViewController alloc] initWithNibName:@"MisListasView" bundle:nil];
    [self.view insertSubview:[self.misListasView view] atIndex:0];

}

- (void)resetAll
{
    self.loginView = nil;
    self.dashboardView = nil;
    self.misListasView = nil;
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.loginView = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
    [self.view insertSubview:[self.loginView view] atIndex:0];
    
    //self.dashboardView = [[DashboardViewController alloc] initWithNibName:@"DashboardView" bundle:nil];
    //[self.view insertSubview:[self.dashboardView view] atIndex:0];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc
{
    [super dealloc];
    [self resetAll];
    self.hashID = nil;
    self.userName = nil;
}

@end
